{% extends "base.html" %}


{% block  title %}资产信息{% endblock %}

{% block page-content %}


    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>资产信息</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="/index.html">主页</a>
                </li>
                <li>
                    <a>资产管理</a>
                </li>
                <li class="active">
                    <strong>资产信息</strong>
                </li>
            </ol>
        </div>
        <div class="col-lg-2">

        </div>
    </div>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>资产信息</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="#">选项 1</a>
                                </li>
                                <li><a href="#">选项 2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                          <div class="table-responsive">

                            <a href="{% url    'asset:asset_add' %}" class="btn btn-primary  ">
                                添加</a>

                            <a class="btn btn-danger" data-toggle="modal"
                               data-target="#myModal2">批量删除
                            </a>





                            <form id="del_form_asset_all" class="form-horizontal  ">
                                <table class="table table-striped table-bordered table-hover dataTables-example">
                                    <thead>
                                    <tr>
                                        <th width="20"><input type="checkbox" id="CheckedAll"></th>
                                        <th>外网IP</th>
                                        <th>管理IP</th>
                                        <th>产品线</th>
                                        <th>数据中心</th>
                                        <th>上联端口</th>
                                        <th>SN</th>
                                        <th>动作{{ error_performance }}</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    {% for   row   in   asset_list %}

                                        <tr class="gradeA" id="{{ row.id }}">
                                            <td><input type="checkbox" value="{{ row.id }}"  name="id"></td>
                                            <td class="center"><a
                                                    href="{% url  "asset:asset_detail"   pk=row.id %}">{{ row.network_ip }}</a>
                                            </td>
                                            <td class="center">{{ row.manage_ip }}</td>
                                            <td class="center">{{  row.product_line.name }}</td>
                                            <td class="center">{{ row.data_center }}</td>
                                            <td class="center">{{ row.uplink_port }}</td>
                                            <td class="center">{{ row.sn }}</td>
                                            <td><a class="btn btn-primary  btn-xs "
                                                   href="{% url  "asset:asset_update"  pk=row.id %}">编辑</a>
                                                <a class="btn btn-danger  btn-xs  asset_del_id"     data-toggle="modal"
                                                        data-target="#myModal1">删除
                                                </a>
                                                <a class="btn btn-primary  btn-xs "
                                                   href="{% url    "asset:asset_performance"   row.id %}">性能</a>
                                                <a type="button" class="btn btn-primary btn-xs  webssh">终端
                                                </a>

                                            </td>
                                        </tr>
                                    {% endfor %}

                                    </tbody>

                                </table>
                            </form>


                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal inmodal" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated fadeIn">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <i class="fa fa-clock-o modal-icon"></i>
                    <h4 class="modal-title">删除</h4>
                    <span id="error" style="color:red;"></span>
                    <small></small>
                </div>
                <form id="asset_del_form">
                    <div class="modal-body">

                        <div class="form-group"><input type="text" name="nid" style="display:none"/></div>
                        <p><strong>确定删除？</strong></p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <a class="btn btn-danger m-r-sm asset_del">删除</a>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <div class="modal inmodal" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated fadeIn">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <i class="fa fa-clock-o modal-icon"></i>
                    <h4 class="modal-title">批量删除</h4>
                    <span id="error_all" style="color:red;"></span>
                    <small></small>
                </div>
                <form id="del_form">
                    <div class="modal-body">

                        <p><strong>确定删除？</strong></p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <a class="btn btn-danger m-r-sm  asset_all_del"> 批量删除</a>
                    </div>
                </form>
            </div>
        </div>
    </div>


    {% block footer-js %}


        <script>
            $(function () {

                $('.asset_del_id').click(function () {
                    var id = $(this).parent().parent().attr('id');
                    $('#asset_del_form').find('input[name="nid"]').val(id);


                });
                $('.asset_del').click(function () {
                    $.ajax({
                        url: "/asset/asset-del.html",
                        type: 'POST',
                        data: $('#asset_del_form').serialize(),
                        success: function (data) {
                            var obj = JSON.parse(data);
                            if (obj.status) {
                                location.reload()
                            } else {
                                $('#error').text(obj.error);
                            }
                        }
                    })
                });

                $('.asset_all_del').click(function () {
                    $.ajax({
                        url: "/asset/asset-all-del.html",
                        type: 'POST',
                        data: $('#del_form_asset_all').serialize(),
                        success: function (data) {
                            var obj = JSON.parse(data);
                            if (obj.status) {
                                location.reload()
                            } else {
                                $('#error_all').text(obj.error);
                            }
                        }

                    })
                });


            });


        $('.webssh').click(function () {

                var id_a = $(this).parent().parent().attr('id');
                $.ajax({
                    url: "/asset/asset-webssh.html",
                    type: 'POST',
                    data: {'id': id_a},
                    success: function (ret) {

                        var obj = JSON.parse(ret);
                        var ip = obj.ip;
                        var username = obj.username;
                        var password = obj.password;

                        $.ajax({
                            url: "http://42.62.6.54:9000/console/login?rnd=" + Math.random(),
                            method: "POST",
                            data: {
                                "vm_addr": ip,
                                "user_name": username,
                                "user_pwd": password
                            },
                            dataType: "jsonp",
                            jsonp: 'callback',
                            jsonpCallback: "callback",
                            cache: false,
                            contentType: "application/json;utf-8", /*设置返回类型*/
                            async: false
                        }).done(function (data) {
                            var json = (data);
                            if (json.ok) {
                                location.href = "http://42.62.6.54:9000" + json.data;
                            } else {
                                alert("登陆失败，请确认您的登陆信息。");
                            }
                        }).fail(function () {
                            alert("未知失败，请联系管理员。");
                        });
                    }
                })
            });


        </script>


    {% endblock %}

{% endblock %}